package Besuperdb;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Properties;

import org.apache.commons.codec.digest.DigestUtils;

import BesuperApp.util.BesuperConsole;

public class BesuperApp {
	private static final String LIST_P = "list -p";
	private static final String LIST_Q = "list -q";
	private static final String LIST_A = "list -a";
	private static final String HELP = "help";
	private static final String ANSWER = "answer";
	private static final String ASK = "ask";
	private static final String SCORE = "score";
	private static final String ACEEPT = "aceept";
	private static final String EXIT = "exit";





	private int id = 0;
	private String name = null;
	private int score = 0;

	public BesuperApp() {
	
	}


    public boolean login(){
    	return false;
    }

	public boolean register() {

		return false;
	}

	public void choose() {
		BesuperConsole.println("Hei man !welcome to the world!");
		while (true) {
			BesuperConsole.println("Do you login or register");
			String str = BesuperConsole.prompt(" you need input l or r ");
			if ("l".equalsIgnoreCase(str)) {
				if (login()) {
					BesuperConsole.println("login success!");
					BesuperConsole.println();
					break;
				} else {
					BesuperConsole.println("Username error, password error, or user does not exist!");
					BesuperConsole.println();
				}
			} else if ("r".equalsIgnoreCase(str)) {
				if (register()) {
					BesuperConsole.println("register success!");
					BesuperConsole.println();
				} else {
					BesuperConsole.println("register failed,the user is exist");
				}
			}
		}
	}

	public void run() {
//		init();

		choose();
		BesuperConsole.println("yo," + name + " nice to see you agian");
		BesuperConsole.println("input 'help' can list the command");
		String command;
		while (true) {
			command = BesuperConsole.prompt("cmd>");
			if (LIST_P.equalsIgnoreCase(command)) {
				listpCommand();
			} else if (LIST_Q.equalsIgnoreCase(command)) {
				listqCommand();
			} else if (LIST_A.equalsIgnoreCase(command)) {
				listaCommand();
			} else if (HELP.equalsIgnoreCase(command)) {
				helpCommand();
			} else if (ANSWER.equalsIgnoreCase(command)) {
				answerCommand();
			} else if (ASK.equalsIgnoreCase(command)) {
				askCommand();
			} else if (SCORE.equalsIgnoreCase(command)) {
				scoreCommand();
			} else if (ACEEPT.equalsIgnoreCase(command)) {
				aceeptCommand();
			} else if (EXIT.equalsIgnoreCase(command)) {
				exitCommand();
				break;
			} else {
				errCommand();
			}

		}

	}

	private void errCommand() {
		BesuperConsole.println("err input,please input a new command");
		BesuperConsole.println("input 'help' can list the command");
	}

	private void exitCommand() {
		BesuperConsole.println("bye  bye");
	}

	private void aceeptCommand() {

	}

	private void scoreCommand() {

	}

	private void askCommand() {

	}

	private void answerCommand() {

	}

	private void helpCommand() {
		BesuperConsole.println("list -p   list the user's username and password and id ");
		BesuperConsole.println("list -q   list the question");
		BesuperConsole.println("list -a   list the answer");
		BesuperConsole.println("help      list the command");
		BesuperConsole.println("answer    Choose a question to answer");
		BesuperConsole.println("ask       create a question");
		BesuperConsole.println("score     show user's score");
	}

	private void listaCommand() {

	}

	private void listqCommand() {

	}

	private void listpCommand() {
		String sql ="select * from plyer";
		
		

	}



}
